/*
 * Copyright (C) 2009 AnK Team
 *	 Andrey Korolev
 *	 Anna Krel
 *	 Anna Kapanina
 *	 
 *	 http://code.google.com/p/ankfood/	
 *    
     
 *    Licensed under the GNU General Public License, Version 2.0 (the "License");
 *
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *         http://www.gnu.org/licenses/gpl-2.0.html

 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,

 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */



package org.ank.food;

import android.app.Activity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Message;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MenuValuesActivity extends Activity{
	

	
	TextView title;
	ListView listView;
	Button okButton;
	ProgressBar protBar, fatBar, carboBar;
	TextView protTitle, fatTitle, carboTitle;
	
	@Override
	public void onCreate(Bundle b){
		super.onCreate(b);
		setContentView(R.layout.menu_values_activity);
		
		setTitle(
				getString(R.string.app_name)+" - "+getString(R.string.title_profile)+": "+
				ProfileManager.getInstance(getApplicationContext()).getCurrentProfileName()
				);
		
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
//				R.layout.advice_list_item/*R.id.profile_list_item_text*/);
		okButton = (Button)findViewById(R.id.menu_values_ok_button);
		
		okButton.setOnClickListener(new Button.OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
    			intent.setClass(getApplicationContext(), EatenTodayActivity.class);
    			startActivity(intent);
				finish();
			} 
		});
		protBar = (ProgressBar)findViewById(R.id.menu_values_protein_progressbar);
		protTitle = (TextView)findViewById(R.id.menu_values_protein_textview);
		fatBar = (ProgressBar)findViewById(R.id.menu_values_fat_progressbar);
		fatTitle = (TextView)findViewById(R.id.menu_values_fat_textview);
		carboBar = (ProgressBar)findViewById(R.id.menu_values_carbo_progressbar);
		carboTitle = (TextView)findViewById(R.id.menu_values_carbo_textview);
		AdviceManager adviceManager = AdviceManager.getInstance(getApplicationContext());
		ProfileManager profileManager = ProfileManager.getInstance(getApplicationContext());
		
		
		int eatenProtEnergy = adviceManager.getEatenProtEnergy();
		int eatenFatEnergy = adviceManager.getEatenFatEnergy();
		int eatenCarboEnergy = adviceManager.getEatenCarboEnergy();
		
		int protQuota = profileManager.getProtQuota();
		int fatQuota = profileManager.getFatQuota();
		int carboQuota = profileManager.getCarboQuota();
		
//		protBar.setIndeterminate(false);
//		protBar.setBackgroundColor(0xFFF);
		protBar.setMax(protQuota);
		protBar.setProgress(eatenProtEnergy);
		protTitle.setText(protTitle.getText().toString()+" "+eatenProtEnergy+" / "+protQuota+" "+
				getString(R.string.energy_unit_name));
		if(eatenProtEnergy > protQuota){
			protTitle.setTextColor(Color.MAGENTA);
			protTitle.setText(protTitle.getText().toString()+getString(R.string.menu_values_exceeded));
		}
		
		fatBar.setMax(fatQuota);
		fatBar.setProgress(eatenFatEnergy);
		fatTitle.setText(fatTitle.getText().toString()+" "+eatenFatEnergy+" / "+fatQuota+" "+
				getString(R.string.energy_unit_name));
		
		if(eatenFatEnergy > fatQuota){
			fatTitle.setTextColor(Color.MAGENTA);
			fatTitle.setText(fatTitle.getText().toString()+getString(R.string.menu_values_exceeded));
		}
		
		carboBar.setMax(carboQuota);
		carboBar.setProgress(eatenCarboEnergy);
		carboTitle.setText(carboTitle.getText().toString()+" "+eatenCarboEnergy+" / "+carboQuota+" "+
				getString(R.string.energy_unit_name));
		
		if(eatenCarboEnergy > carboQuota){
			carboTitle.setTextColor(Color.MAGENTA);
			carboTitle.setText(carboTitle.getText().toString()+getString(R.string.menu_values_exceeded));
		}
	}
	
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent();
			intent.setClass(getApplicationContext(), EatenTodayActivity.class);
			startActivity(intent);
			finish();
			return true;
		}
	    return super.onKeyDown(keyCode, event);
	}
	

}
